import unittest
import requests

class TestRegister(unittest.TestCase):
    def setUp(self):
#实例化session
        self.session = requests.Session()
        self.url="https://hmshop-test.itheima.net/Home/User/reg.html"
        # self.headers = {"content-Type": "application/x-www-form-urlencoded"}
    def tearDown(self):
        self.session.close()
    def test01_register(self):
        resp_verify = self.session.get("https://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify&type=user_reg&r=0.1783493367988095")
        #断言响应头中包含image
        self.assertIn("image",resp_verify.headers.get("Content-Type"))
        #使用session发送注册的请求
        resp = self.session.post("https://hmshop-test.itheima.net/Home/User/reg.html",
                            data={"scene": "1", "username": "15634457329", "verify_code": "8888", "password": "123456",
                                  "password2": "123456", "invite": ""})
        #断言响应状态码
        self.assertEqual(200, resp.status_code)
        #断言响应体 status
        self.assertEqual(1,resp.json().get('status'))
        #断言响应体 msg
        self.assertEqual("注册成功",resp.json().get('msg'))
        #打印注册结果
        print("注册的结果为：",resp.json())






